<?php
echo '<pre>'.($ddl = slObject::create(new User(), null, true)).'</pre>';
assert_equal("CREATE TABLE IF NOT EXISTS `FooBar` (
/* field name: */ `userId` /* data type: */ BIGINT /* unsigned: */ UNSIGNED /* zerofill: */  /* null: */ NULL /* auto_increment: */ AUTO_INCREMENT /* unique: */  /* primary: */ PRIMARY KEY /* comment: */  ,
/* field name: */ `username` /* data type: */ VARCHAR(256) /* unsigned: */  /* zerofill: */  /* null: */ NOT NULL /* auto_increment: */  /* unique: */  /* primary: */  /* comment: */  ,
/* field name: */ `passwordHash` /* data type: */ CHAR(32) /* unsigned: */  /* zerofill: */  /* null: */ NULL /* auto_increment: */  /* unique: */  /* primary: */  /* comment: */  ,
/* field name: */ `created` /* data type: */ DATETIME /* unsigned: */  /* zerofill: */  /* null: */ NULL /* auto_increment: */  /* unique: */  /* primary: */  /* comment: */  ,
/* field name: */ `enabled` /* data type: */ BIT /* unsigned: */  /* zerofill: */  /* null: */ NULL /* auto_increment: */  /* unique: */  /* primary: */  /* comment: */  ,
/* field name: */ `blob` /* data type: */ BLOB /* unsigned: */  /* zerofill: */  /* null: */ NULL /* auto_increment: */  /* unique: */  /* primary: */  /* comment: */ COMMENT 'This is my rifle, this is my gun.  This is for fighting, this is for fun.',
/* field name: */ `integer` /* data type: */ INTEGER /* unsigned: */  /* zerofill: */ ZEROFILL /* null: */ NULL /* auto_increment: */  /* unique: */  /* primary: */  /* comment: */  ,
`employeeId` BIGINT UNSIGNED, INDEX(`employeeId`)
) type=InnoDB
CREATE TABLE IF NOT EXISTS `FooBar_PasswordHistory` ( `oneId` BIGINT UNSIGNED, `manyId` BIGINT UNSIGNED, INDEX(`oneId`), INDEX(`manyId`), INDEX(`oneId`,`manyId`) ) type=InnoDB
CREATE TABLE IF NOT EXISTS `jobType_FooBar` ( `oneId` BIGINT UNSIGNED, `manyId` BIGINT UNSIGNED, INDEX(`oneId`), INDEX(`manyId`), INDEX(`oneId`,`manyId`) ) type=InnoDB
CREATE TABLE IF NOT EXISTS `FooBar_action` ( `FooBarId` BIGINT UNSIGNED, `actionId` BIGINT UNSIGNED, INDEX(`FooBarId`), INDEX(`actionId`), INDEX(`FooBarId`,`actionId`) ) type=InnoDB", $ddl);
slObject::create(new User());


echo '<pre>'.($ddl = slObject::create(new Password(), null, true)).'</pre>';
assert_equal("CREATE TABLE IF NOT EXISTS `PasswordHistory` (
/* field name: */ `passwordId` /* data type: */ BIGINT /* unsigned: */  /* zerofill: */  /* null: */ NULL /* auto_increment: */ AUTO_INCREMENT /* unique: */  /* primary: */ PRIMARY KEY /* comment: */  ,
/* field name: */ `passwordHash` /* data type: */ CHAR(32) /* unsigned: */  /* zerofill: */  /* null: */ NOT NULL /* auto_increment: */  /* unique: */  /* primary: */  /* comment: */  ,
/* field name: */ `created` /* data type: */ DATETIME /* unsigned: */  /* zerofill: */  /* null: */ NOT NULL /* auto_increment: */  /* unique: */  /* primary: */  /* comment: */  
) type=InnoDB
CREATE TABLE IF NOT EXISTS `FooBar_PasswordHistory` ( `oneId` BIGINT UNSIGNED, `manyId` BIGINT UNSIGNED, INDEX(`oneId`), INDEX(`manyId`), INDEX(`oneId`,`manyId`) ) type=InnoDB", $ddl);


echo '<pre>'.($ddl = slObject::create(new Employee(), null, true)).'</pre>';
assert_equal("CREATE TABLE IF NOT EXISTS `employee` (
/* field name: */ `employeeId` /* data type: */ BIGINT /* unsigned: */  /* zerofill: */  /* null: */ NULL /* auto_increment: */ AUTO_INCREMENT /* unique: */  /* primary: */ PRIMARY KEY /* comment: */  ,
/* field name: */ `firstName` /* data type: */ VARCHAR(1024) /* unsigned: */  /* zerofill: */  /* null: */ NULL /* auto_increment: */  /* unique: */  /* primary: */  /* comment: */  ,
/* field name: */ `lastName` /* data type: */ VARCHAR(1024) /* unsigned: */  /* zerofill: */  /* null: */ NULL /* auto_increment: */  /* unique: */  /* primary: */  /* comment: */  ,
/* field name: */ `hired` /* data type: */ DATETIME /* unsigned: */  /* zerofill: */  /* null: */ NULL /* auto_increment: */  /* unique: */  /* primary: */  /* comment: */  ,
`FooBarId` BIGINT UNSIGNED, INDEX(`FooBarId`)
) type=InnoDB", $ddl);
slObject::create(new Employee());

echo '<pre>'.($ddl = slObject::create(new JobType(), null, true)).'</pre>';
assert_equal("CREATE TABLE IF NOT EXISTS `jobType` (
/* field name: */ `name` /* data type: */ VARCHAR(1024) /* unsigned: */  /* zerofill: */  /* null: */ NULL /* auto_increment: */  /* unique: */  /* primary: */  /* comment: */  ,
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY
) type=InnoDB
CREATE TABLE IF NOT EXISTS `jobType_FooBar` ( `oneId` BIGINT UNSIGNED, `manyId` BIGINT UNSIGNED, INDEX(`oneId`), INDEX(`manyId`), INDEX(`oneId`,`manyId`) ) type=InnoDB", $ddl);

$user = new User();
$user->username = 'acollegeman';
$user->created = 'Oct. 26, 1981';
$dml = $user->save(true);
assert_equal($dml, "INSERT INTO `FooBar` (`username`, `passwordHash`, `created`, `enabled`, `blob`, `integer`) VALUES ('acollegeman', null, '1981/10/26 00:00:00', null, null, null)");

$dml = $user->save(true);
assert_equal($dml, "INSERT INTO `FooBar` (`username`, `passwordHash`, `created`, `enabled`, `blob`, `integer`) VALUES ('acollegeman', null, '1981/10/26 00:00:00', null, null, null)");

$dml = $user->delete(true);
assert_equal($dml, "DELETE FROM `FooBar` WHERE `userId`=null");

$dml = $user->deleteAll(true);
assert_equal($dml, "DELETE FROM `FooBar`");

$ddl = $user->drop(new User(), null, true);
assert_equal($ddl, "DROP TABLE IF EXISTS `FooBar`");

$dql = $user->select('WHERE created > %c ORDER BY created DESC', 'Oct. 26 1981', 10, 1, true);
assert_equal($dql, "SELECT * FROM `FooBar` WHERE created > '1981/10/26 00:00:00' ORDER BY created DESC LIMIT 10 OFFSET 1");

$dql = $user->getAll('ORDER BY username', 250, true);
assert_equal($dql, "SELECT * FROM `FooBar` ORDER BY username LIMIT 250 OFFSET 0");
